/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package item;

import java.util.List;
import javax.persistence.*;
import myJPA.Model;
import transactions.Rental;
import transactions.Reservation;


/**
 *
 * @author ZIZI
 */
@Entity
@Table(name="item")
@NamedQueries
({
@NamedQuery(name="findItem", query="select i from Item i where title=:title"),
@NamedQuery(name="getAllItems", query="select i from Item i"),
})
public class Item extends Model{
    @Id
    @GeneratedValue
    private int id;
    
    @OneToMany
    @JoinColumn(name = "item_id", referencedColumnName = "id")
    private List<Rental> rentals;
    
    @OneToMany
    @JoinColumn(name = "item_id", referencedColumnName = "id")
    private List<Reservation> reservations;
    
    
    @Column(nullable=false)
    private String title;
    @Column(nullable=false)
    private String author;
    @Column(nullable=false)
    private String producer;
    @Column(nullable=false)
    private String genre;
    @Column(nullable=false)
    private int productionYear;
    @Column(nullable=false)
    private int numberCopies;
    @Column(nullable=false)
    private int availableCopies;
    @Column(nullable=false)
    private String type;

    public Item() {
        super();
    }

    public Item(String title, String author, String producer, String genre, int productionYear, int numberCopies, String type) {
        this.title = title;
        this.author = author;
        this.producer = producer;
        this.genre = genre;
        this.productionYear = productionYear;
        this.numberCopies = numberCopies;
        this.type = type;
        this.availableCopies = numberCopies;
    }

    

    /**
     * @return the id
     */
    
    
    
    
    public List<Rental> getRentals() {
        return rentals;
    }

    public void setRentals(List<Rental> rentals) {
        this.rentals = rentals;
    }

    public List<Reservation> getReservations() {
        return reservations;
    }

    public void setReservations(List<Reservation> reservations) {
        this.reservations = reservations;
    }
    
    
    public int getId() {
        return id;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the numberCopies
     */
    public int getNumberCopies() {
        return numberCopies;
    }

    /**
     * @param numberCopies the numberCopies to set
     */
    public void setNumberCopies(int numberCopies) {
        this.numberCopies = numberCopies;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the availableCopies
     */
    public int getAvailableCopies() {
        return availableCopies;
    }

    /**
     * @param availableCopies the availableCopies to set
     */
    public void setAvailableCopies(int availableCopies) {
        this.availableCopies = availableCopies;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Item other = (Item) obj;
        if (this.id != other.id) {
            return false;
        }
        if ((this.title == null) ? (other.title != null) : !this.title.equals(other.title)) {
            return false;
        }
        if (this.numberCopies != other.numberCopies) {
            return false;
        }
        if (this.availableCopies != other.availableCopies) {
            return false;
        }
        if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        return hash;
    }

    /**
     * @return the author
     */
    public String getAuthor() {
        return author;
    }

    /**
     * @param author the author to set
     */
    public void setAuthor(String author) {
        this.author = author;
    }

    /**
     * @return the producer
     */
    public String getProducer() {
        return producer;
    }

    /**
     * @param producer the producer to set
     */
    public void setProducer(String producer) {
        this.producer = producer;
    }

    /**
     * @return the genre
     */
    public String getGenre() {
        return genre;
    }

    /**
     * @param genre the genre to set
     */
    public void setGenre(String genre) {
        this.genre = genre;
    }

    /**
     * @return the productionYear
     */
    public int getProductionYear() {
        return productionYear;
    }

    /**
     * @param productionYear the productionYear to set
     */
    public void setProductionYear(int productionYear) {
        this.productionYear = productionYear;
    }
    
    
}

